package com.spring.cloud.weatherbasic.controller;

import com.spring.cloud.weatherbasic.service.CityDataService;
import com.spring.cloud.weatherbasic.service.WeatherReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * Created by Administrator on 2018/3/17
 */
@Controller
@RequestMapping("/report")
public class WeatherReportController {

    @Autowired
    private CityDataService cityDataService;

    @Autowired
    private WeatherReportService weatherReportService;

    @GetMapping("/cityId/{cityId}")
//    public ModelAndView getReportByCityId(@PathVariable("cityId") String cityId, Model model) throws Exception {
    public ModelAndView getReportByCityId(@PathVariable("cityId") String cityId, Map<String, Object> map) throws Exception {
//        model.addAttribute("title", "慕课网的天气预报");
//        model.addAttribute("cityId", cityId);
//        model.addAttribute("cityList", cityDataService.listCity());
//        model.addAttribute("report", weatherReportService.getDataByCityId(cityId));
//        return new ModelAndView("weather/report", "reportModel", model);
        map.put("title", "慕课网的天气预报");
        map.put("cityId", cityId);
        map.put("cityList", cityDataService.listCity());
        map.put("report", weatherReportService.getDataByCityId(cityId));

        return new ModelAndView("weather/report", map);
    }

}
